<template>
    <div id="FamilyOrigin">
        <div style="margin-bottom: 10px">
            <el-button @click="intoNewsAdmin()">添加新闻</el-button>
        </div>
        <el-table
                :data="newsData.filter(newsData => !search || newsData.title.toLowerCase().includes(search.toLowerCase()))"
                height="660"
                :highlight-current-row="true"
                :size="medium"
                >
            <el-table-column
                    label="序号"
                    type="index"
                    width="60"
                    align="center"
            >
            </el-table-column>
<!--            <el-table-column-->
<!--                    prop="id"-->
<!--                    label="id"-->
<!--                    width="55">-->
<!--            </el-table-column>-->
            <el-table-column
                    prop="title"
                    label="标题"
            >
            </el-table-column>
            <el-table-column
                    prop="content"
                    label="内容"
                    width="400px">
            </el-table-column>
            <el-table-column
                    prop="publisher"
                    label="发布人"
            >
            </el-table-column>
            <el-table-column
                    prop="releaseDateTime"
                    label="发布时间"
            >
            </el-table-column>
            <el-table-column
                    prop="updateDateTime"
                    label="上一次修改时间">
            </el-table-column>
            <el-table-column
                    align="right">
                <!-- eslint-disable-next-line -->
                <template slot="header" slot-scope="scope">
                    <el-input
                            v-model="search"
                            size="mini"
                            placeholder="输入关键字搜索"/>
                </template>
                <!-- eslint-disable-next-line -->
                <template  slot-scope="scope">
                    <el-button type="primary" icon="el-icon-edit" circle>
                    </el-button>
                    <el-button type="danger" icon="el-icon-delete" circle>
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>

    export default {
        name: "FamilyOrigin",
        data() {
            return {
                search: '',
                token: localStorage.getItem('TOKEN'),
                userInfo: {},
                newsData: [],
            }
        },
        created() {
            this.showNews();
        },

        methods: {
            //跳转到添加资讯的页面 ——> 传当前登录的管理员的id
            intoNewsAdmin() {
                this.$router.push({path: '/AddNews', query: {id: this.userInfo.id}});
            },
            //    获取资讯列表，以及用户token
            showNews() {
                this.$axios.get('/api/user/token', {headers: {TOKEN: this.token}}).then(res => {
                    this.userInfo = res.data.data;
                    // this.id = res.data.data.id;
                    //展示资讯列表
                    this.$axios.get('/api/news/checkall?adminId=' + this.userInfo.id).then(res => {
                        if (res.data.status === 1) {
                            this.newsData = res.data.data;
                            this.$message.success(res.data.msg);
                        } else {
                            this.$message.error(res.data.msg);
                        }
                    })
                });
            },
        }
    }
</script>

<style lang="scss">

</style>